home *** CD-ROM | disk | FTP | other *** search
- Path: mailhub.scitec.com.au!ramsesy
- From: ramsesy@rd.scitec.com.au (Ramses Youhana)
- Newsgroups: comp.lang.c
- Subject: Re: a pointer problem
- Date: 16 Feb 1996 07:04:21 GMT
- Organization: SCITEC LIMITED, Sydney, Australia.
- Distribution: world
- Message-ID: <4g1a9l$l5@mailhub.scitec.com.au>
- References: <4errk0$4c3@srvr1.engin.umich.edu> <31120AB7.1C44@cmt.lpr.mail.carel.fi> <4et96h$k84@sparcserver.lrz-muenchen.de>
- NNTP-Posting-Host: scitec7.scitec.com.au
- X-Newsreader: TIN [version 1.2 PL2]
-
- Kurt Watzka (ua302aa@sun2.lrz-muenchen.de) wrote:
- > Ari Lukumies <aril@cmt.lpr.mail.carel.fi> writes:
-
- > >Chih-Jen Lin wrote:
- > >>
- > >> Hi,
- > >>
- > >> This is an old problem of C. I remember a pointer may point
- > >> to any one address when it's declaired. Is there any way to
- > >> avoid this problem in ANSI C ? Or how can I let a variable be
- > >> NULL while it's declaired ?
- > >>
- > >> Thanks in advance.
- > >>
- > >> Chih-Jen Lin
-
- > >You'll have to explicitly initialize the pointer, ANSI C (or any other standard)
- > >doesn't do it for you. However, most compilers tend to initialize variables (also
- > >pointers) declared outside of any function scope (or 'static' variables inside
- > >functions) to zero/NULL, but I wouldn't count on it.
-
- > I would and sometimes do count on initialization of static and global
- > variables, as long as I work with an ANSI C compiler. Initialization
- > happens "as if" through assigning 0 to the variable, so this kind of
- > initialization is save for pointers and floating point variables, too.
-
- It is dangerous to rely on the compiler to do initialisation of static
- and global variables in embedded systems. This is usually the case when
- you write your own boot code and don't include the appropriate routine(s)
- which read the data out of the appropriate section (sometimes called the
- IDATA or INITDATA section) and copies to the appropriate RAM locations
- to initialise your variables.
-
- I always find it better (and safer) design to perform my own initialisations
- in an initialisation function.
-
- Ramses.
-